const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const userApi = require('./api/userApi');

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.all('*', function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Content-Type','application/json;charset=UTF-8');
    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

    if (req.method == 'OPTIONS') {
        res.send(200);
    } else {
        next();
    }
});

//设置后端路由
app.use('/api/user', userApi);

app.listen(3000, () => {
	console.log("正在监听3000端口");
});
